﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLSVPT1h
{
    public partial class ThayDoiQD : Form
    {
        public ThayDoiQD()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        public SqlConnection con;
        private void Form2_Load(object sender, EventArgs e)
        {
            string connectionString = "Data Source=.;Initial Catalog=QLHS;Integrated Security=True";
            con = new SqlConnection(connectionString);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string commandString;
            SqlCommand com;
            int i = -1;
            string a = textBox1.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 5 && i <= 12)
            {
                commandString = "update QUYDINH set SoLopThuocKhoi = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
            a = textBox2.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 100 && i <= 500)
            {
                commandString = "update QUYDINH set SoHocSinhThuocKhoi = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
            a = textBox3.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 30 && i <= 100)
            {
                commandString = "update QUYDINH set TongSoLop = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
            a = textBox4.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 20 && i <= 50)
            {
                commandString = "update QUYDINH set SoHocSinhThuocLop = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
            a = textBox5.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 100 && i <= 3000)
            {
                commandString = "update QUYDINH set TongSoHocSinh = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
            a = domainUpDown1.Text;
            commandString = "update QUYDINH set TuoiToiThieu = " + a;
            con.Open();
            com = new SqlCommand(commandString, con);
            com.ExecuteNonQuery();
            con.Close();
            a = domainUpDown2.Text;
            commandString = "update QUYDINH set TuoiToiDa = " + a;
            con.Open();
            com = new SqlCommand(commandString, con);
            com.ExecuteNonQuery();
            con.Close();
            a = textBox6.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 0 && i <= 10)
            {
                commandString = "update QUYDINH set DiemChuanMon = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
            a = textBox7.Text;
            if (a == "")
                i = -1;
            else
                i = Convert.ToInt16(a);
            if (i >= 5 && i <= 10)
            {
                commandString = "update QUYDINH set SoGiaoVienThuocMon = " + a;
                con.Open();
                com = new SqlCommand(commandString, con);
                com.ExecuteNonQuery();
                con.Close();
            }
        }

        private void ThayDoiQD_FormClosed(object sender, FormClosedEventArgs e)
        {
            Homepage_Form hp = new Homepage_Form();
            this.Visible = false;
            hp.Show();
        }
    }
}
